# -*- coding: utf-8 -*-
#Importamos modulos standards
import datetime
from django.contrib.auth.models import User, AnonymousUser
from django.contrib.sessions.models import Session
#Importamos nuestros modulos
from mundofacu.usuarios.models import carreras, mensajes
from mundofacu.usuarios.formularios import Flogin
from mundofacu.usuarios.funciones import exist
from mundofacu.foro.models import subforos, threads, posts
from mundofacu.portal.models import colores


#Definimos nuestros contextos
def is_mod(usr):
	if not isinstance(usr,AnonymousUser): return (usr.get_profile().tipo_usuario >= 3)


def get_colors(usr):
	if isinstance(usr,AnonymousUser): return colores.objects.get(user=0)
	elif exist(colores,"user",usr): return colores.objects.get(user=usr)
	else: return colores.objects.get(user=0)


def general(request):
	if request.user.username == "admin": usr= "administrador"
	else: usr= request.user.username
	return {
		'sitio': "Mundofacu.com",
		'adminmail': "mundofacu@gmail.com",
		'usr' : usr,
		'colores': get_colors(request.user),
		'logged': not isinstance(request.user,AnonymousUser),
		'is_mod': is_mod(request.user),
		'cregistrados': User.objects.count(),
		'cloggeados': User.objects.filter(last_login__gte=datetime.date.today()).count(),
		'carreras': carreras.objects.all(),
		'subforos': subforos.objects.all(),
		'csubforos': subforos.objects.count(),
		'cthreads': threads.objects.count(),
		'ccomentarios': posts.objects.count(),
		'msgcount': str(mensajes.objects.filter(receptor=request.user.id,leido=False).count()),
		'save': "Enviar",
		}